//
//  GroupMemberTableViewCell.m
//  Findif
//
//  Created by Mac on 2019/2/27.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "GroupMemberTableViewCell.h"

@interface GroupMemberTableViewCell ()

@property (nonatomic, weak)UIView * backView;
@property (nonatomic, weak)UILabel * nameLabel;
@property (nonatomic, weak)UIImageView * iconImageView;
@property (nonatomic, weak)UIView * lineView;
@property (nonatomic, weak)UIImageView * genderImageView;
@property (nonatomic, weak)UIImageView * shupImageView;

@end

@implementation GroupMemberTableViewCell


- (void)setModel:(MyAttentionModel *)model{
    
    _model = model;
    
    self.nameLabel.text = model.attention_user_name;
    NSString * imgStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,model.head_img];
    NSURL * url = [NSURL URLWithString:imgStr];
    [self.iconImageView sd_setImageWithURL:url];
    
    int sex = [model.sex intValue];
    
    if (sex == 1) {
        
        self.genderImageView.image = [UIImage imageNamed:@"男性"];
    }else{
        
        self.genderImageView.image = [UIImage imageNamed:@"女性"];
    }
    
    self.shupImageView.hidden = YES;
}

- (void)setMemberModel:(MemberModel *)memberModel{
    
    _memberModel = memberModel;
    
    self.nameLabel.text = memberModel.user_name;
    NSString * imgStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,memberModel.head_img];
    NSURL * url = [NSURL URLWithString:imgStr];
    [self.iconImageView sd_setImageWithURL:url];
    
    int sex = [memberModel.sex intValue];
    
    if (sex == 1) {
        
        self.genderImageView.image = [UIImage imageNamed:@"男性"];
    }else{
        
        self.genderImageView.image = [UIImage imageNamed:@"女性"];
    }
    
    int is_banned = [memberModel.is_banned intValue];
    
    if (is_banned == 1) {
        
        self.shupImageView.hidden = NO;
    }else{
        
        self.shupImageView.hidden = YES;
    }
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = ColorWithRGB(0xF4F5F6);
    
    UIView * backView = [UIView new];
    
    backView.backgroundColor  =ZRWhiteColor;
    backView.layer.cornerRadius = 5 * SCREENH6;
    backView.layer.masksToBounds = YES;
    backView.userInteractionEnabled = YES;
    
    self.backView = backView;
    
    [self.contentView addSubview:self.backView];
    
    
    UIImageView * iconImageView = [UIImageView new];
    
    iconImageView.backgroundColor = [UIColor grayColor];
    iconImageView.layer.cornerRadius = 20 * SCREENH6;
    iconImageView.layer.masksToBounds = YES;
    
    self.iconImageView = iconImageView;
    
    [self.backView addSubview:self.iconImageView];
    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.textColor = ZRBlackColor;
    nameLabel.text = @"用户姓名";
    nameLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    self.nameLabel = nameLabel;
    
    [self.backView addSubview:self.nameLabel];
    
    
    UIImageView * genderImageView = [UIImageView new];
    
    genderImageView.image = [UIImage imageNamed:@"男性"];
    
    self.genderImageView = genderImageView;
    
    [self.backView addSubview:self.genderImageView];
    
    UIImageView * shupImageView = [UIImageView new];
    
    shupImageView.image = [UIImage imageNamed:@"禁言"];
    
    self.shupImageView = shupImageView;
    
    [self.backView addSubview:self.shupImageView];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe4e4e4);
    
    self.lineView = lineView;
    
    [self.backView addSubview:self.lineView];
}

- (void)layoutSubviews{
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.centerX.mas_equalTo(self.contentView);
        make.width.mas_equalTo(345 * SCREENH6);
        make.height.mas_equalTo(60 * SCREENH6);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backView);
        make.leading.mas_equalTo(self.backView).offset(10 * SCREENH6);
        make.width.height.mas_equalTo(40 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).offset(10 * SCREENH6);
        make.top.mas_equalTo(self.iconImageView).offset(3 * SCREENH6);
    }];
    
    [self.genderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(5 * SCREENH6);
        make.height.width.mas_equalTo(13 * SCREENH6);
    }];
    
    [self.shupImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.backView);
        make.trailing.mas_equalTo(self.backView).offset(-10 * SCREENH6);
        make.width.height.mas_equalTo(22 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iconImageView);
        make.trailing.mas_equalTo(self.shupImageView);
        make.bottom.mas_equalTo(self.backView);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
